﻿using DongHuMgmt.Bussiness.Abstract;
using DongHuMgmt.Bussiness.Concrete;
using DongHuMgmt.Common.Models;
using DongHuMgmt.DataAccess;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DongHuMgmt.Web.Controllers
{
    public class LoginController : BaseController
    {
        private static ILog log = LogManager.GetLogger(typeof(LoginController));

        private ISysUserService _ISysUserService;

        public LoginController(ISysUserService sysUserService)
        {
            this._ISysUserService = sysUserService;
        }

        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(LoginUserModel loginUserModel)
        {
            if (ModelState.IsValid)
            {
                SysUser user = _ISysUserService.FindUserByLoginNameAndPassword(loginUserModel.LoginName, loginUserModel.Password);
                if (user != null) 
                {
                    HttpContext.Session["user"] = user;
                }
                
                return Redirect("/Home/Index");
            }
            else
            {
                return View();
            }
        }
    }
}